from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from django.conf import settings

def dumps(json,expires):

    # 创建工具对象
    serializer=Serializer(settings.SECRET_KEY,expires)
    # 加密
    s1 = serializer.dumps(json)
    # 转字符串，返回
    return s1.decode()





def loadds(s1, expires):
    serializer = Serializer(settings.SECRET_KEY, expires)
    try:
        json = serializer.loads(s1)
    except:
        return None
    return json
